package exception;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class TestDriver7 {
    public static void main(String[] args) {

        test01();
        System.out.println("===try，catch，catch，finally==异常处理===");
        test02();
        System.out.println("===try，catch，finally==异常处理===");
        test02();
    }

    /**
     * 异常处理的分类
     */
    //定义一个静态成员变量
    static String stuName;//默认值是空null

    public  static void test01() /*throws FileNotFoundException */{
        //建立一个文件操作流输出类
        //检查性异常
        //FileOutputStream fileOutputStream = new FileOutputStream("D:\\temp\\filesdemo");//创建一个文件夹，检查文件是否异常
        //非检查性异常
//        int i = 0;
//        int j = 4;
//        int k =j/i;
//        System.out.println("k="+k);

        System.out.println(stuName == null?"null":stuName.toUpperCase());//如果不为空，发生异常

    }

    public static void test02(){
        //建立文件操作操作流输出类
        //检查性异常
        System.out.println("=======执行try-catch-catch语句============");
        try{
            FileOutputStream fileOutputStream = new FileOutputStream("E:\\temp\\filesdemo\\text.txt");
        } catch (FileNotFoundException e) {
            System.out.println("发生了异常："+e.getMessage());
            e.printStackTrace();
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
        finally {
            //收尾
            System.out.println("执行了finally部分");
        }
    }

    public static void test21(){
        //建立一个文件操作流输出类
        //检查性异常
        System.out.println("========try-catch语句===============");
        try{FileOutputStream fileOutputStream = new FileOutputStream("E:\\temp\\filesdemo\\text.txt");
        } catch (FileNotFoundException e) {
            System.out.println("发生异常："+e.getMessage());
            e.printStackTrace();
        }finally {
            //收尾
            System.out.println("执行了finally部分");
        }
    }
}
